const carts={
	state:{
		cartList:[]
	},
	mutations:{
		setCartList(state,params){
			let {item,num}=params;
			let cartItem={
				goodsId:item.id || item.goodsId,
				numValue:num,
				name:item.name,
				price:item.price,
				thumb:item.thumb,
				before_price:item.before_price
			}
			
			let idx=state.cartList.findIndex(cart=>{
				return cart.goodsId==cartItem.goodsId;
			})
			
			if(idx<0){
				state.cartList.unshift(cartItem)
			}else{
				state.cartList[idx].numValue=cartItem.numValue;
				if(state.cartList[idx].numValue<=0) state.cartList.splice(idx,1);
			}
			
			
		}
	}
}

export default carts;